// pages/01homePage/03foodOrder/foodOrder.js
var app = getApp()
var appData = app.globalData
Page({
   data: {
      order: '',
      foodNum: 0,
      totalPrice: 0,
      shopInfo:''       //店铺信息
   },

   onLoad: function (options) {
      var obj = JSON.parse(options.order)
      this.countNumAndPrice(obj)
      this.setData({
         shopInfo: appData.shopInfo,
      })
      
   },

   countNumAndPrice: function (obj) {
      var num = 0
      var price = 0
      for (var i = 0; i < obj.order.length; i++) {
         num += obj.order[i].num * 1
         price += (obj.order[i].price * obj.order[i].num)
      }
      this.setData({
         order: obj,
         foodNum: num,
         totalPrice: price
      })
   },

   addFood: function () {
      wx.navigateBack()
   },
   //提交菜单 
   submitOrder: function (e) {
      var that = this
      var e_v = e.detail.value
      if (e_v.renshu == 0) {
         app.toast('请输入用餐人数')
         return
      }
      console.log("【店铺信息】", this.data.shopInfo)
      console.log("【【】】", this.data.order.order)
      var param = this.data.order
      // 创建订单提交字段
      param.Address_Province = ''                        //省份编号
      param.Address_Area = ''                            //市区编号
      param.Address_City = ''                            //城市编号
      param.Address_Detailed = ''                        //详细地址
      param.Address_Mobile = ''                          //收货人手机
      param.Address_Name = ''                            //收获人姓名
      param.Biz_ID = appData.shopInfo.Biz_ID             //商家ID
      param.Coupon_Cash = ''                             //优惠券抵现金
      param.Coupon_ID = ''                               //使用优惠券ID
      param.Integral_Consumption = ''                    //积分使用条件
      param.Integral_Get = ''                            //商品积分
      param.Integral_Money = ''                          //积分条件税换
      param.Is_User_Distribute = ''                      //买家是否分销商
      param.Order_CartList = ''                          //产品数量
      param.Order_InvoiceInfo = ''                       //发票信息
      param.Order_IsVirtual = ''                         //是否虚拟订单
      param.Order_NeedInvoice = ''                       //是否需要发票
      param.Order_Remark = ''                            //订单备注
      param.Order_Shipping = ''                          //快递
      param.Order_Status = ''                            //订单状态
      param.Order_TotalAmount = ''                       //订单原总价
      param.Order_TotalPrice = this.data.totalPrice      //订单现总价
      param.Order_Type = ''                              //订单类型
      param.Owner_ID = ''                                //推荐人ID
      param.User_ID = ''                                 //用户ID
      param.Web_Price = ''                               //网站所得
      param.Web_Pricejs = ''                             //网站所得
      param.curagio_money = ''                           //会员折扣
      param.Table_ID = appData.guestInfo.rcduid          //餐桌ID
      param.Seat_Fee = appData.shopInfo.Seat_Fee         //餐位费
      param.Guest_Num = e_v.renshu                       //用餐人数

      param.dec = e_v.dec
      console.log("【输出param】===", param)
      // app.getJsonData('order/Omg/create', param, function (res) {
      //    that.readySendSocket(param, res.data)
      //    app.noticeUpdateTableList(res.data)
      //    app.noticeTicket(param.zhuo)
      //    wx.navigateBack({ delta: 2 })
      // })
      // Order_CartList.push({
      //    Product_ID: PRO[i].Cart_List[j].Product_ID,
      //    Sku_ID: PRO[i].Cart_List[j].Property_shu_vid,
      //    QTY: PRO[i].Cart_List[j].Qty
      // })
   },
   //准备发送wss
   readySendSocket: function (p, rd) {
      //msg数组结构：0桌号, 1状态, 2订单号, 3订单价格, 4点菜数量,5人数
      var m = {
         msg: rd,
         setMsg: p.fenlei + p.zhuohao + '桌开席了'
      }
      var params = {
         order_id: rd[2],
         seat_fee: p.seat_fee,
         shop_name: p.uid,
         table_name: p.fenlei + p.zhuohao,
         type: p.command == 'add' ? 1 : 0,//0打印全部，1打印加菜
         needImg: 0//是否要图片：0不，1要
      }
      console.log('准备发送wss的m==', m)
      var json = {
         type: 'say',
         to_client_id: 'all',
         content: JSON.stringify(m),
         param: params
      }
      var msg = JSON.stringify(json)
      appData.isWsSender = 1
      app.sendSocketMsg(msg)
   },
})